본문 바로가기

select7

Hello SQL World! Hello SQL! Return a table with a single column named Greeting with the phrase 'hello world!' Please use Data Manipulation Language and not Data Definition Language to solve this Kata Solution: SELECT 'hello world!' AS "Greeting" The reason 'Greeting' is enclosed in double quotation marks is that uppercase letters are changed to lowercase letters unless they are enclosed in double quotation marks.. 2022. 7. 17.
Even or Odd SQL Notes: You will be given a table, numbers, with one column number. Return a table with a column is_even containing "Even" or "Odd" depending on number column values. numbers table schema number INT output table schema is_even STRING Solution: SELECT CASE WHEN number%2=0 THEN 'Even' ELSE 'Odd' END AS is_even FROM numbers In psql, 'if' is 'case when ~ then ~ else ~'. 2022. 5. 19.
Easy SQL: LowerCase Given a demographics table in the following format: ** demographics table schema ** id name birthday race you need to return the same table where all letters are lowercase in the race column. Solution: SELECT id, name, birthday, LOWER(race) as race FROM demographics; 2022. 5. 13.
SQL Basics: Simple WHERE and ORDER BY For this challenge you need to create a simple SELECT statement that will return all columns from the people table WHERE their age is over 50 people table schema id name age You should return all people fields where their age is over 50 and order by the age descending NOTE: Your solution should use pure SQL. Ruby is used within the test cases to do the actual testing. Solution: SELECT * FROM peo.. 2022. 5. 12.
SQLAlchemy 1.x 와 2.0의 Query 스타일 비교 SQLAlchemy 2.0 SQLAlchemy 2.0에서는 query를 생성할 때 2.0 스타일을 사용할 수 있습니다. 2.0 스타일은 기존의 Session.query()가 아닌 select() 등의 메소드로 생성한 쿼리를 Session.execute()로 전달하여 DB와 통신할 수 있습니다. 현재 공식문서에서는 기존 스타일의 ORM을 제거할 계획은 없다고 하며, 어떤 스타일이든 함께 사용할 수 있다고 합니다. 다만, SQLAlchemy를 비동기로 구현할 경우 AsyncSession 클래스는 Session.query()를 지원하지 않으므로 2.0 스타일을 사용해야합니다. Within the ORM, 2.0 style query execution is supported, using select() cons.. 2022. 4. 25.
SQLAlchemy에서의 비동기 쿼리 (feat. 2.0 Style) AsyncSession을 통한 비동기 DB 통신 SQLAlchemy 에서는 DB와 비동기로 통신하기 위해서 AsyncSession 을 사용합니다. 그런데 AsyncSession을 사용하게 되면 ORM방식도 바뀌는데요. SQLAlchemy 공식문서에서는 2.0 스타일 쿼리를 사용한다고 합니다. Synopsis - ORM Using 2.0 style querying, the [AsyncSession] class provides full ORM functionality. Within the default mode of use, special care must be taken to avoid lazy loading or other expired-attribute access involving ORM relati.. 2022. 4. 24.