简体   繁体   中英

What is the dollar sign $ in rails log mean for SQL?

I'm having trouble understanding why there is a $1 instead of 123 , which is the id I put in.

Foo Load (0.4ms)  SELECT  "foos".* FROM "foos" WHERE "foos"."id" = $1 LIMIT 1  [["id", 123]]
Doorkeeper::Application Load (0.4ms)  SELECT "oauth_applications".* 
  FROM "oauth_applications" WHERE "oauth_applications"."id" IN (SELECT DISTINCT "oauth_access_tokens"."application_id" 
  FROM "oauth_access_tokens" WHERE "oauth_access_tokens"."resource_owner_id" = $1
  AND "oauth_access_tokens"."revoked_at" IS NULL)  [["resource_owner_id", 123]]

The $1 in your output represents a positional argument such as ["id", 123] , which includes the id you put into your query.

ie from the PostgreSQL docs :

A dollar sign ($) followed by digits is used to represent a positional parameter in the body of a function definition or a prepared statement. In other contexts the dollar sign may be part of an identifier or a dollar-quoted string constant.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM